
/*   RolGPS Project
 * 
 *   Copyright (C) 2009 Pablo Alejandro Costesich <rhfixer@gmail.com>
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */
package org.rolgps.libnlink.connection;

import java.util.Observable;
import java.util.Observer;
import org.rolgps.libnlink.protocol.CommEventHandler;
import org.rolgps.libnstack.protocol.Message;

/**
 *
 * @author xeph
 */
public class CommEvent implements Observer {

    Message master = null;
    CommEventHandler commEvent;
    /**
     *
     */
    public final static String SHUTDOWN = "messenger shutdown";
    /**
     *
     */
    public final static String EXCEPTION = "aieeee!";

    /**
     *
     * @param commEvent
     */
    public CommEvent(CommEventHandler commEvent) {
        this.commEvent = commEvent;
    }

    /**
     *
     * @param arg0
     * @param arg1
     */
    public void update(Observable arg0, Object arg1) {
        if (arg1 instanceof Message) {
            master = (Message) arg1;
            commEvent.newMessage(master);
            
        } else if (arg1 instanceof String) {
            String argument = (String) arg1;
            if (argument.equals(SHUTDOWN)) {
                commEvent.messengerShutdown();
            }
        }else if (arg1 instanceof String) {
            String argument = (String) arg1;
            if (argument.equals(EXCEPTION)) {
                
            }
        } else if (arg1 instanceof ConnectionProperties) {
            commEvent.assignedProperties((ConnectionProperties) arg1);
        }
    }
}
